package com.wei800.turnover.action;

import com.wei800.common.action.abs.AbstractBaseAction;
import com.wei800.common.http.ResponseData;
import com.wei800.common.util.bean.DeepBeanUtils;
import com.wei800.dto.MemberDTO;
import com.wei800.service.IMemberService;
import com.wei800.turnover.entity.Member;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/member/")
@Slf4j
public class MemberAction extends AbstractBaseAction { // 必须要继承父类
    @Autowired
    private IMemberService memberService;

    @RequestMapping("list")
    public Object list() {
        log.info("执行用户列表操作");
        return this.memberService.list();
    }

    @RequestMapping("add") // 写路径
    public Object add(@RequestBody MemberDTO memberDTO) {
        log.info("执行用户增加操作");
        ResponseData responseData = new ResponseData();
        responseData.setRespCode(HttpStatus.OK.value()); // HTTP响应状态码
        Member member = new Member();
        DeepBeanUtils.copyProperties(memberDTO, member);
        responseData.setRespData(this.memberService.save(member)); // HTTP响应内容
//        throw new RuntimeException("hello");
        return responseData;
    }
}
